import Vue from 'vue'
import Router from 'vue-router'

const Login = () => import(/* webpackChunkName:"Login_Home_Welcome" */ '../components/Login.vue')
const Home = () => import(/* webpackChunkName:"Login_Home_Welcome" */ '../components/Home.vue')
const Welcome = () => import(/* webpackChunkName:"Login_Home_Welcome" */ '../components/Welcome.vue')
// import Login from '../components/Login.vue'
// import Home from '../components/Home.vue'
// import Welcome from '../components/Welcome.vue'
const Users = () => import(/* webpackChunkName:"User_Roles_Rights" */ '../components/Users/Users.vue')
const Roles = () => import(/* webpackChunkName:"User_Roles_Rights" */ '../components/power/Roles.vue')
const Rights = () => import(/* webpackChunkName:"User_Roles_Rights" */ '../components/power/Rights.vue')
// import Users from '../components/Users/Users.vue'
// import Roles from '../components/power/Roles.vue'
// import Rights from '../components/power/Rights.vue'
const Goods = () => import(/* webpackChunkName:"Goods_GoodsAdd_GoodsEdit" */ '../components/goods/Goods.vue')
const GoodsAdd = () => import(/* webpackChunkName:"Goods_GoodsAdd_GoodsEdit" */ '../components/goods/GoodsAdd.vue')
const GoodsEdit = () => import(/* webpackChunkName:"Goods_GoodsAdd_GoodsEdit" */ '../components/goods/GoodsEdit.vue')
// import Goods from '../components/goods/Goods.vue'
// import GoodsAdd from '../components/goods/GoodsAdd.vue'
// import GoodsEdit from '../components/goods/GoodsEdit.vue'
const Categories = () => import(/* webpackChunkName:"Categories_Params" */ '../components/goods/Categories.vue')
const Params = () => import(/* webpackChunkName:"Categories_Params" */ '../components/goods/Params.vue')
// import Categories from '../components/goods/Categories.vue'
// import Params from '../components/goods/Params.vue'
const Orders = () => import(/* webpackChunkName:"Orders_Report" */ '../components/orders/Orders.vue')
const Report = () => import(/* webpackChunkName:"Orders_Report" */ '../components/report/Report.vue')
// import Orders from '../components/orders/Orders.vue'
// import Report from '../components/report/Report.vue'

Vue.use(Router)

const router = new Router({
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', component: Login },
    {
      path: '/home',
      component: Home,
      redirect: '/welcome',
      children: [
        {
          path: '/welcome',
          component: Welcome
        },
        {
          path: '/users',
          component: Users
        },
        {
          path: '/roles',
          component: Roles
        },
        {
          path: '/rights',
          component: Rights
        },
        {
          path: '/goods',
          component: Goods
        },
        {
          path: '/goods/add',
          component: GoodsAdd
        },
        {
          path: '/goods/edit',
          component: GoodsEdit
        },
        {
          path: '/categories',
          component: Categories
        },
        {
          path: '/params',
          component: Params
        },
        {
          path: '/orders',
          component: Orders
        },
        {
          path: '/reports',
          component: Report
        }
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
  // 访问login页面放行
  if (to.path === '/login') return next()
  // 获取token之后放行home
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})
export default router
